package com.mmall.controller;

import com.mmall.service.ICartService;
import entity.Const;
import entity.ResponseCode;
import entity.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Cart;
import pojo.User;
import vo.CartVo;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private ICartService iCartService;

    @GetMapping("/add/{count}/{productId}")
    public ServerResponse<CartVo> add(HttpSession session, @PathVariable("count") Integer count, @PathVariable("productId") Integer productId){
//        User user = (User)session.getAttribute(Const.CURRENT_USER);
//        if(user == null){
//            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN.getDesc());
//        }
        //return iCartService.add(user.getId(), productId, count);
        return iCartService.add(1, productId, count);
    }

    @GetMapping("/selectChkById/{userId}")
    public List<Cart> selectChkById(@PathVariable("userId") Integer userId) {
        return iCartService.selectChkById(userId);
    }
}
